package com.miage.m1.xml.project;

import java.util.Date;

import org.xml.sax.ContentHandler;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.AttributesImpl;

public class Person {
	
	private final String firstName;
	private final String lastName;
	private final String nationality;
	private final Date birthday;
	private double pay;
	
	protected AttributesImpl atts = new AttributesImpl();

	/* Constructors */
	
/**
 * 
 * @param lastName
 * @param firstName
 * @param nationality
 * @param birthday
 * @param pay
 */
	public Person(String lastName, String firstName, String nationality, Date birthday, double pay){
		this.firstName = firstName;
		this.lastName = lastName;
		this.nationality = nationality;
		this.birthday = birthday;
		this.pay = pay;
		
	}
	
	public Person(String firstName, String lastName, String nationality, Date birthday){
		this(firstName, lastName, nationality, birthday, 0);
	}
	
	
	/* Getters */
	
	public String getLastName(){
		return this.lastName;
	}
	
	public String getFirstName(){
		return this.firstName;
	}
	
	public String getNationality(){
		return this.nationality;
	}
	
	public Date getBirthday() {
		return birthday;
	}
	
	public double getPay(){
		return this.pay;
	}
	
	public void setPay(double pay){
		this.pay = pay;
	}
	
	
	
	/* Methods and Properties*/
	
	/**
	 * Serialize a Person
	 * @param handler
	 * @return
	 * @throws SAXException
	 */
	public ContentHandler Serialize(ContentHandler handler) throws SAXException{
		//TODO Create the serialization of a Player.
		if(handler == null){
			throw new SAXException("Pas de ContentHandler");
		}
		
		handler.startElement("", "firstName", "firstName", atts);
		char[] firstName = this.getFirstName().toCharArray();
		handler.characters(firstName,0,firstName.length);
		handler.endElement("", "firstName", "firstName");
		
		handler.startElement("", "lastName", "lastName", atts);
		char[] lastName = this.getLastName().toCharArray();
		handler.characters(lastName,0,lastName.length);
		handler.endElement("", "lastName", "lastName");
		
		handler.startElement("", "nationality", "nationality", atts);
		char[] nationality = this.getNationality().toCharArray();
		handler.characters(nationality,0,nationality.length);
		handler.endElement("", "nationality", "nationality");
		
		handler.startElement("", "age", "age", atts);
		char[] age = String.valueOf(this.getAge()).toCharArray();
		handler.characters(age, 0, age.length);
		handler.endElement("", "age", "age");
		
		
		return handler;
	}
	
	public int getAge(){
		return 20; //TODO Calcul de l'age
	}
}
